<template>
    <div class="mymg-tb">
        <div class="bor inleft" @click="substring">-</div>
        <div class="bor incenter" v-text="count"></div>
        <div class="bor inright" @click="addend">+</div>
    </div>
</template>

<script>
export default {
    props:['initCount','goodsid'],
    data() {
        return {
            count:1,
            resObj:{goodsid:0,type:'add'}     //定义一个对象 包含商品id和   操作（加或减）
        }
    },
    created(){
        this.count = this.initCount;
    },
    methods: {
        substring() {
            this.count--;
            if (this.count < 1) {
                this.count = 1;
                return;               
            }
             this.getmessage('substring');
        },
        addend() {
            this.count++;
            this.getmessage('add');
        },
        getmessage(type) {
            this.resObj.goodsid = this.goodsid;
            this.resObj.type = type;
            this.$emit('cardataObj', this.resObj);
        }
    }
}
</script>

<style scoped>
.bor {
    width: 50px;
    height: 25px;
    text-align: center;
    float: left;
    line-height: 25px;
    margin: 0px 2px;
    border: 1px solid #099;
}
</style>